﻿@using BlazorMonaco.Editor
@*page:PrintTemplateEdit.razor*@
@*gardener-time:2024-09-24 14:36:25*@
@inherits EditOperationDialogBase<PrintTemplateDto, Guid,PrinterLocalResource>
<style>
    .my-editor-class {
        min-height: 70Vh;
    }
</style>
<Form @ref="_editForm"
      Loading="_dialogLoading.Value"
      Model="_editModel"
      LabelCol="new ColLayoutParam { Span = 6 }"
      WrapperCol="new ColLayoutParam { Span = 18 }"
      OnFinish="OnFormFinish"
      ValidateMode="FormValidateMode.Complex"
      Context="model">
    <Tabs DefaultActiveKey="1" Type="@TabType.Line">
        <TabPane Key="baseInfo" Tab="@Localizer[nameof(PrinterLocalResource.BasicInformation)]" Closable="false">
            @if (base.OperationIs(OperationDialogInputType.Edit | OperationDialogInputType.Select))
            {
                <FormItem>
                    <Input @bind-Value="model.Id" Disabled="true" />
                </FormItem>

            }
            <ResourceAuthorize ResourceKey="@CommonResourceKeys.SystemTenantAdministratorKey">
                <FormItem Label="@Localizer[nameof(SharedLocalResource.Tenant)]">
                    <Select DataSource="_tenants"
                            @bind-Value="model.TenantId"
                            ValueName="@nameof(SystemTenantDto.Id)"
                            LabelName="@nameof(SystemTenantDto.Name)"
                            TItem="SystemTenantDto"
                            TItemValue="Guid?"
                            AllowClear
                            Disabled="base.operationIsOnlyReadData">
                    </Select>
                </FormItem>
            </ResourceAuthorize>
            <FormItem Rules="[_uniqueValueValidatorRule]">
                <Input @bind-Value="model.TemplateKey" Disabled="base.operationIsOnlyReadData" />
            </FormItem>
            <FormItem>
                <Select DataSource="DictHelper.GetCodesFromCache<PrintTemplateDto>(() => model.TemplateType)"
                        @bind-Value="model.TemplateType"
                        ValueName="@nameof(CodeDto.CodeValue)"
                        LabelName="@nameof(CodeDto.CodeName)"
                        TItem="CodeDto"
                        TItemValue="string"
                        AllowClear
                        Disabled="base.operationIsOnlyReadData">
                </Select>
            </FormItem>
            <FormItem>
                <Input @bind-Value="model.TemplateName" Disabled="base.operationIsOnlyReadData" />
            </FormItem>
            <FormItem>
                <InputNumber @bind-Value="model.TemplateHeight" Disabled="base.operationIsOnlyReadData" />
            </FormItem>
            <FormItem>
                <InputNumber @bind-Value="model.TemplateWidth" Disabled="base.operationIsOnlyReadData" />
            </FormItem>
            <FormItem>
                <Input @bind-Value="model.TemplatePreviewImage" Disabled="base.operationIsOnlyReadData" Style="display:none;" />
                @if (UploadParams != null)
                {
                    <Gardener.Core.Client.Components.MultiFileUpload UploadParams="UploadParams" @bind-FileList="FileList" />
                }
            </FormItem>
            <FormItem>
                <Select DataSource="EnumHelper.EnumToDictionary<TemplateResultType>()"
                        TItem="KeyValuePair<TemplateResultType,string>"
                        TItemValue="TemplateResultType"
                        ItemValue="x=>x.Key"
                        ItemLabel="x=>Localizer[x.Value]"
                        @bind-Value="model.TemplateResultType"
                        Disabled="base.operationIsOnlyReadData">
                </Select>
            </FormItem>
            <FormItem>
                <ResourceAuthorize ResourceKey="system_manager_print_template_lock">
                    <Authorized>
                        <Switch @bind-Value="@model.IsLocked" Disabled="base.operationIsOnlyReadData"></Switch>
                    </Authorized>
                    <NotAuthorized>
                        <Switch @bind-Value="@model.IsLocked" Disabled="true"></Switch>
                    </NotAuthorized>
                </ResourceAuthorize>
            </FormItem>

            <ResourceAuthorize ResourceKey="@CommonResourceKeys.SystemTenantAdministratorKey">
                <Authorized>
                    <FormItem>
                        <Switch @bind-Value="@model.EmpowerAllTenants" Disabled="base.operationIsOnlyReadData"></Switch>
                    </FormItem>
                </Authorized>
            </ResourceAuthorize>
            @if (this.Options.Type.Equals(OperationDialogInputType.Edit) || this.Options.Type.Equals(OperationDialogInputType.Select))
            {
                <FormItem Label="@Localizer[nameof(SharedLocalResource.CreatedTime)]">
                    <span>@model.CreatedTime.ToString(ClientConstant.DateTimeFormat)</span>
                </FormItem>

            }

            @if (this.Options.Type.Equals(OperationDialogInputType.Edit) || this.Options.Type.Equals(OperationDialogInputType.Select))
            {
                <FormItem Label="@Localizer[nameof(SharedLocalResource.UpdatedTime)]">
                    <span>@model.UpdatedTime?.ToString(ClientConstant.DateTimeFormat)</span>
                </FormItem>

            }
        </TabPane>
        <TabPane Key="template" Tab="@Localizer[nameof(PrinterLocalResource.TemplateContent)]" Closable="false">
            <StandaloneCodeEditor @ref="_templateContentEditor" Id="ed1" ConstructionOptions="TemplateEditorConstructionOptions" CssClass="my-editor-class" />
        </TabPane>
    </Tabs>
    <FormItem WrapperColOffset="8" WrapperColSpan="16">
        <Space>
            @if (!OperationDialogInputType.Select.Equals(this.Options.Type))
            {
                <SpaceItem>
                    <Button Type="@ButtonType.Primary" OnClick="OnGoToSubmit">
                        @Localizer[nameof(SharedLocalResource.Save)]
                    </Button>
                </SpaceItem>
            }
            <SpaceItem>
                <Button OnClick="_=>OnFormCancel()">
                    @Localizer[nameof(SharedLocalResource.Cancel)]
                </Button>
            </SpaceItem>
        </Space>
    </FormItem>
</Form>